﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Unsupported;
using Phone.Controls;

namespace ScotiabankWP7.Forms.Transferencias
{
    public partial class TransfCtaTercero : PhoneApplicationPage
    {
        private PickerBoxDialog dialogCargo;
        private PickerBoxDialog dialogAbono;
        private string[] data = null;
        private int selectedIndex;   

        public TransfCtaTercero()
        {
            InitializeComponent();

            txtCompraVenta.Text = "TC: Compra = S/. 2.7965 Venta = S/. 2.8035";
            txtFecha.Text = "18/02/2001 18:50:52";

            TiltEffect.SetIsTiltEnabled(this, true);

            data = GetCuentasArray();
            this.bCuentaCargo.DataContext = data[0];
            this.bCuentaAbono.DataContext = data[0];

            InitPickerBoxDialogCargo();
            InitPickerBoxDialogAbono();  
        }

        private void InitPickerBoxDialogCargo()
        {
            dialogCargo = new PickerBoxDialog();
            // Assign data source and title
            dialogCargo.ItemSource = data;
            dialogCargo.Title = "cuentas bancarias";
            // Hook up into closed event
            dialogCargo.Closed += new EventHandler(dialogCargo_Closed);
        }

        void dialogCargo_Closed(object sender, EventArgs e)
        {
            selectedIndex = dialogCargo.SelectedIndex;
            // Dialog closed. Assign the value to the button
            this.bCuentaCargo.DataContext = data[selectedIndex];
        }

        private void InitPickerBoxDialogAbono()
        {
            dialogAbono = new PickerBoxDialog();
            // Assign data source and title
            dialogAbono.ItemSource = data;
            dialogAbono.Title = "cuentas bancarias";
            // Hook up into closed event
            dialogAbono.Closed += new EventHandler(dialogAbono_Closed);
        }

        void dialogAbono_Closed(object sender, EventArgs e)
        {
            selectedIndex = dialogAbono.SelectedIndex;
            // Dialog closed. Assign the value to the button
            this.bCuentaAbono.DataContext = data[selectedIndex];
        }

        private string[] GetCuentasArray()
        {
            string[] data = new string[10];
            data[0] = "AHMN 123-4567890 S/. 250.55";
            data[1] = "AHME 000-4588899 S/. 580.00";
            data[2] = "AHME 000-4588899 S/. 1580.00";
            data[3] = "AHME 000-4588899 S/. 480.00";
            data[4] = "AHME 000-4588899 S/. 45880.00";
            data[5] = "AHME 000-4588899 S/. 896.00";
            data[6] = "AHME 000-4588899 S/. 1234.00";
            data[7] = "AHME 000-4588899 S/. 6696.00";
            data[8] = "AHME 000-4588899 S/. 15900.00";
            data[9] = "AHME 000-4588899 S/. 82.00";
            return data;
        }          

        private void bCuentaCargo_Click(object sender, RoutedEventArgs e)
        {
            // Display dialog
            dialogCargo.SelectedIndex = selectedIndex;
            dialogCargo.Show();
        }

        private void bCuentaAbono_Click(object sender, RoutedEventArgs e)
        {
            // Display dialog
            dialogAbono.SelectedIndex = selectedIndex;
            dialogAbono.Show();
        }

        private void btnSiguiente_Click(object sender, RoutedEventArgs e)
        {
            PhoneApplicationFrame root = Application.Current.RootVisual as PhoneApplicationFrame;
            root.Navigate(new Uri("/Forms/Transferencias/TransfVerificacion.xaml", UriKind.Relative));
        }   
    }
}